<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>JK服装轮播</title>
        <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    </head>
    <style>
        *{
            padding: 0;
            margin: 0;
            list-style: none;
        }
        body{
            background: rgb(218, 216, 216);
        }
        ul{
            width: 9999px;
            position:relative;
        
        }
        #long{
            margin: 0 auto;
            overflow: hidden;
            width: 400px;
            height: 650px;
            border: 1px solid black;
            position:relative;
        }
        #long img{
            border-radius: 1%;
            position: absolute;
            float: left;
            width: 400px;
            height: 650px;
        }
        i{
            color: black;
            width: 50px;
            height: 50px;
            background: rgb(142, 142, 143);
            opacity:0.4;
            border-radius: 50%;
        }
        i:nth-of-type(1){
            position: absolute;
            left: 0;
            top:50%;
        }
        i:nth-of-type(2){
            position: absolute;
            right: 0;
            top:50%;
        }
        .glyphicon{
            line-height: 50px;
            font-size: 25px;
        }
        .glyphicon:hover{
            opacity:0.7;
        }
        .glyphicon-chevron-left::before{
            left: 12px;
            position: relative
        }
        .glyphicon-chevron-right::before{
            left: 12px;
            position: relative
        }
        ol{
            overflow: hidden;
            width: 100px;
            margin: 0 auto;
            padding-top: 10px;
        }
        ol li{
            border: 1px solid black;
            float: left;
            width: 15px;
            height: 15px;
            border-radius: 50%;
            margin: 0 3px;
        }
    </style>
    <script>
        window.onload=function(){
            var box=document.getElementsByTagName('img')
            var li=document.getElementsByTagName('li')
            var timer
            doSome()
            function init(){//初始化
                n=0
                for(var i=0;i<box.length;i++){
                    box[i].style.left=n+'px'
                    n+=400
                }
            }
            init()
            function doSome(){
                num=0
                timer=setInterval(function(){
                    num++
                    if(num>=4){
                        num=0
                        init()
                    }else{
                        for(var i=0;i<box.length;i++){
                            var left=box[i].style.left
                            left=parseFloat(left)
                            if(left<=-1200){
                                init()
                                num=0
                            }
                            box[i].style.left=left-400+'px'
                        }
                    }
                    for(var i=0;i<li.length;i++){
                        li[i].style.background='none'
                        if(i==num){
                            li[i].style.background='black'
                        }
                        li[i].onclick=function(){
                            console.log(li[i])
                        }
                    }
                },2000)
            }
            document.getElementById('long').onmouseenter=function(){//鼠标移入停止
                clearInterval(timer)
            }
            document.getElementById('long').onmouseleave=function(){//鼠标移出开始
                doSome()
            }
        }
    </script>
    <body>
        <div id="long">
            <ul>
                <img src="img/jk0.jpg" alt="">
                <img src="img/jk1.jpg" alt="">
                <img src="img/jk2.jpg" alt="">
                <img src="img/jk3.jpg" alt="">
            </ul>
            
            <i class="glyphicon glyphicon-chevron-left"></i>
            <i class="glyphicon glyphicon-chevron-right"></i>
        </div>
        <ol>
            <li style="background: black;"></li>
            <li></li>
            <li></li>
            <li></li>
        </ol>
    </body>
</html>